package com.ruoyi.project.app.aspect.handler;

import com.ruoyi.project.app.anno.NotNull;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Parameter;

public class NotNullHandler implements Handler{
    @Override
    public boolean handler(AnnotatedElement element, Object obj) {
        NotNull notNull = null;
        if(element instanceof Parameter){
            Parameter  parameter = (Parameter) element;
            notNull = parameter.getAnnotation(NotNull.class);
        }else if(element instanceof Field){
            Field field = (Field) element;
            notNull = field.getAnnotation(NotNull.class);
        }

        if (notNull != null && obj == null) {
            throw new RuntimeException(notNull.msg());
        }
        return false;
    }
}
